/*
 * Credits.java
 *
 *  created: 12.10.2011
 *  charset: UTF-8
 *  license: MIT (X11) (See LICENSE file for full license)
 */
package cz.mp.k3bg;

import static cz.mp.k3bg.Application.EOL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Vytváří seznam autorů a přispěvatelů.
 *
 * @author Martin Pokorný
 * @version 0.1
 */
public class Credits {
   
    private static final List<Author> AUTHORS;
    static {
        ArrayList<Author> authors = new ArrayList<Author>();

        authors.add(new Author("Martin Pokorn\u00fd",   // Martin Pokorný
                "MartinPokorny.czech@gmail.com",//"MartinPokorny@email.cz",/
                getLocText("gui.about.credits.role.author")
                ));

        // * sem přidat ...
        
        AUTHORS = Collections.unmodifiableList(authors);
    }

    /** */
    private Credits() {
    }

    /**
     *
     * @return
     */
    public static String getCreditsText() {
        StringBuilder sb = new StringBuilder();
        sb.append("<html>\n");
        for (Author author : AUTHORS) {

            sb.append("<b>").append(author.getName()).append("</b>");

            if (author.getEmail() != null) {
//                sb.append(" &lt;");
                sb.append(" (");
                sb.append("<a href=\"mailto:")
                        .append(author.getEmail())
                        .append("?subject=").append(Application.NAME)
                        .append("\">");
                sb.append(author.getEmail());
                sb.append("</a>");
                sb.append(") ");
//                sb.append("&gt; ");
            }
            
            sb.append(" <br>").append(EOL);

            String[] roles = author.getRoles();
            if (roles.length > 0) {
//                sb.append(" (");
                for (int i=0; i<roles.length-1; i++) {
                    sb.append(roles[i]).append(", ");
                }
                sb.append(roles[roles.length-1]);
//                sb.append(")");
            }
            
            sb.append(" <br><br>").append(EOL);
        }
        sb.append("</html>");
        return sb.toString();
    }

    /** */
    protected static String getLocText(String key, Object... args) {
        return TextSource.getLocText(key, args);
    }

    // -------------------------------------------------------------------------

    /**
     *
     */
    private static class Author {
        String name;
        String email;
        String[] roles;

        public Author(String name, String email, String... roles) {
            if (name == null || name.isEmpty()) {
                throw new IllegalArgumentException("name is empty");
            }
            this.name = name;
            this.email = email;
            this.roles = roles;
        }

        public String getName() {
            return name;
        }

        public String getEmail() {
            if (email == null || email.isEmpty()) {
                return null;
            }
            return email;
        }

        public String[] getRoles() {
            return roles;
        }

        @Override
        public String toString() {
            return name + " (" + Arrays.toString(roles) + ")";
        }
    }   // Author

}   // Credits
